
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region CompanyDAL
	public class CompanyDAL : DBContext
	{
		public List<Company> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CompaniesSelectAll");
            return GetEntityList<Company>(cmd);
        }

        public Company GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CompanySelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<Company>(cmd);
        }

		public List<Company> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CompanySelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<Company>(cmd);
        }

        public Company Add(string paramName, string paramDescription, int paramCentralWarehouseId, string paramAddress1,
                                   string paramAddress2, string paramAddress3, string paramPostCode, int paramCountryId, int paramCityId,
                                  string paramTel, string paramFax, string paramWebsite, string paramEmail, string paramCompanyRegisterationNo,
                                  string paramGSTNo, string paramSoftwareLisence, DateTime paramSoftwareStartDate, DateTime paramSoftwareExpiryDate,
                                  string paramLogoPath)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CompanyInsert");
            cmd.AddParameter("@Name", paramName);
            cmd.AddParameter("@Description", paramDescription);
            cmd.AddParameter("@CentralWarehouseId", paramCentralWarehouseId);
            cmd.AddParameter("@Address1", paramAddress1);
            cmd.AddParameter("@Address2", paramAddress2);
            cmd.AddParameter("@Address3", paramAddress3);
            cmd.AddParameter("@PostCode", paramPostCode);
            cmd.AddParameter("@CountryId", paramCountryId);
            cmd.AddParameter("@CityId", paramCityId);
            cmd.AddParameter("@Tel", paramTel);
            cmd.AddParameter("@Fax", paramFax);
            cmd.AddParameter("@Website", paramWebsite);
            cmd.AddParameter("@Email", paramEmail);
            cmd.AddParameter("@CompanyRegisterationNo", paramCompanyRegisterationNo);
            cmd.AddParameter("@GSTNo", paramGSTNo);
            cmd.AddParameter("@SoftwareLisence", paramSoftwareLisence);
            cmd.AddParameter("@SoftwareStartDate", paramSoftwareStartDate);
            cmd.AddParameter("@SoftwareExpiryDate", paramSoftwareExpiryDate);
            cmd.AddParameter("@LogoPath", paramLogoPath);
            return GetSingleEntity<Company>(cmd);
        }

        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CompanyDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public Company UpdateById(Guid paramId, string paramName,string paramDescription,int paramCentralWarehouseId,string paramAddress1,
                                   string paramAddress2, string paramAddress3, string paramPostCode, int paramCountryId, int paramCityId,
                                  string paramTel, string paramFax,	string paramWebsite, string paramEmail,	string paramCompanyRegisterationNo,
                                  string paramGSTNo, string paramSoftwareLisence, DateTime paramSoftwareStartDate,	DateTime paramSoftwareExpiryDate,
                                  string paramLogoPath)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CompanyUpdate");
			cmd.AddParameter("@Id", paramId);
			cmd.AddParameter("@Name", paramName);
			cmd.AddParameter("@Description", paramDescription);
			cmd.AddParameter("@CentralWarehouseId", paramCentralWarehouseId);
			cmd.AddParameter("@Address1", paramAddress1);
			cmd.AddParameter("@Address2", paramAddress2);
			cmd.AddParameter("@Address3", paramAddress3);
			cmd.AddParameter("@PostCode", paramPostCode);
			cmd.AddParameter("@CountryId", paramCountryId);
			cmd.AddParameter("@CityId", paramCityId);
			cmd.AddParameter("@Tel", paramTel);
			cmd.AddParameter("@Fax", paramFax);
			cmd.AddParameter("@Website", paramWebsite);
			cmd.AddParameter("@Email", paramEmail);
			cmd.AddParameter("@CompanyRegisterationNo", paramCompanyRegisterationNo);
			cmd.AddParameter("@GSTNo", paramGSTNo);
			cmd.AddParameter("@SoftwareLisence", paramSoftwareLisence);
			cmd.AddParameter("@SoftwareStartDate", paramSoftwareStartDate);
			cmd.AddParameter("@SoftwareExpiryDate", paramSoftwareExpiryDate);
			cmd.AddParameter("@LogoPath", paramLogoPath);
            return GetSingleEntity<Company>(cmd);
        }
		
	}
	#endregion
}
